<?php

#<editor-fold defaultstate="collapsed" desc="start">
ini_set('max_execution_time', 2);
include 'core/core.php';
#</editor-fold>

CCore::Using('base.datapointer');

echo '<pre>';

$file = 'examples/eml/simple with attachment.eml';
$text = 'MIME-Version: 1.0
Message-ID: <45a92f7.0e89f233c32fbd2b9d191d4cb28775c9@domain.com>
From: from@domain.com
To: test@domain.com
Subject: TEST HTML MESSAGE WITH ATTACHMENT
Date: Thu, 6 May 2010 07:26:37 -0700 (PDT)
Content-Type: multipart/mixed;
	boundary="--=_NextPart_11de424d3d872ac110be4ecfffc45411"

----=_NextPart_11de424d3d872ac110be4ecfffc45411
Content-Type: text/html;
	charset="utf-8"
Content-Transfer-Encoding: Quoted-Printable

<html><body>TEST HTML MESSAGE WITH ATTACHMENT</body></html>

----=_NextPart_11de424d3d872ac110be4ecfffc45411
Content-Type: image/gif;
	name="av-7.gif"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="av-7.gif"

R0lGODdhMgAyAOfXAAAAADMAAGYAAJkAAMwAAP8AAAAzADMzAGYzAJkzAMwzAP8zAABmADNmAGZm
AJlmAMxmAP9mAACZADOZAGaZAJmZAMyZAP+ZAADMADPMAGbMAJnMAMzMAP/MAAD/ADP/AGb/AJn/
AMz/AP//AAAAMzMAM2YAM5kAM8wAM/8AMwAzMzMzM2YzM5kzM8wzM/8zMwBmMzNmM2ZmM5lmM8xm
M/9mMwCZMzOZM2aZM5mZM8yZM/+ZMwDMMzPMM2bMM5nMM8zMM//MMwD/MzP/M2b/M5n/M8z/M///
MwAAZjMAZmYAZpkAZswAZv8AZgAzZjMzZmYzZpkzZswzZv8zZgBmZjNmZmZmZplmZsxmZv9mZgCZ

----=_NextPart_11de424d3d872ac110be4ecfffc45411--
';
$b = '----=_NextPart_11de424d3d872ac110be4ecfffc45411';

$q = new CCoreBaseDataPointer();
$q->InitByString($text);

$mm = $q->Search("\r\n\r\n");
$d = $q->GetPartAsDataPointer($mm);

var_dump($d);

$s = 0;
$a = array();
while (true)
{
	$p = $d->Search($b, $s);
	if (false !== $p)
	{
		$a[] = $d->GetPartAsDataPointer($s, $p - $s);
		$s = $p + strlen($b);
	}
	else
	{
		break;
	}
}

foreach ($a as $da)
{
var_dump($da->GetString());
}

